// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: fengyang

#include "coin2/exchange/base/feed/subscriber.h"
#include "coin2/exchange/base/feed/timer/timer_subscriber.h"
#include "coin2/exchange/base/feed/timer/timer_manager.h"

namespace coin2::exchange::base::feed::timer {
namespace impl {
using coin2::exchange::base::feed::FeedUpdate;

TimerFeedSubscriber::TimerFeedSubscriber(
    exchange::base::feed::IFeedSubscriber* subscriber,
    TimerManager* manager)
    : subscriber_(subscriber),
      manager_(manager) {
}
void TimerFeedSubscriber::InjectFeed(const FeedSubsystemManager* feed_mgr) {
  subscriber_->InjectFeed(feed_mgr);
}
void TimerFeedSubscriber::onTradeFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onTradeFeed(upd);
}
void TimerFeedSubscriber::onLiquidationFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onLiquidationFeed(upd);
}
void TimerFeedSubscriber::onOpenInterestFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onOpenInterestFeed(upd);
}
void TimerFeedSubscriber::onMarkPriceFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onMarkPriceFeed(upd);
}
void TimerFeedSubscriber::onIndexFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onIndexFeed(upd);
}
void TimerFeedSubscriber::onFundingRateFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onFundingRateFeed(upd);
}
void TimerFeedSubscriber::onIvGreeksFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onIvGreeksFeed(upd);
}
void TimerFeedSubscriber::onNavFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onNavFeed(upd);
}
void TimerFeedSubscriber::onWalletFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onWalletFeed(upd);
}
void TimerFeedSubscriber::onMarketAnalysisFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onMarketAnalysisFeed(upd);
}
void TimerFeedSubscriber::onTopLongShortAccountRatioFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onTopLongShortAccountRatioFeed(upd);
}
void TimerFeedSubscriber::onTopLongShortPositionRatioFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onTopLongShortPositionRatioFeed(upd);
}
void TimerFeedSubscriber::onGlobalLongShortAccountRatioFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onGlobalLongShortAccountRatioFeed(upd);
}
void TimerFeedSubscriber::onTakerBuySellRatioFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onTakerBuySellRatioFeed(upd);
}
void TimerFeedSubscriber::onOpenInterestHistFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onOpenInterestHistFeed(upd);
}
void TimerFeedSubscriber::onBookFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onBookFeed(upd);
}
void TimerFeedSubscriber::onKlineFeed(const FeedUpdate& upd) {
  UpdateTimestamp(upd.timestamp());
  subscriber_->onKlineFeed(upd);
}

void TimerFeedSubscriber::onHeartbeatFeed(const FeedTimer& timer) {
  // never called
  NOTREACHED();
  subscriber_->onHeartbeatFeed(timer);
}

void TimerFeedSubscriber::UpdateTimestamp(int64_t now) {
  manager_->Tick(now);
}

}  // namespace impl
}  // namespace coin2::exchange::base::feed::timer
